using Avalonia.BiliBili.ViewModels;
using Avalonia.Extensions.Controls;
using Avalonia.Extensions.Event;
using Bilibili.Model.Channel;
using Bilibili.Model.Common;
using System;
using System.Diagnostics;

namespace Avalonia.BiliBili.Windows
{
    public partial class DynamicTopicWindow : WindowBase
    {
        private DynamicTopicViewModel ViewModel { get; }
        public DynamicTopicWindow()
        {
            InitializeComponent();
            ViewModel = new DynamicTopicViewModel();
        }
        protected override void AfterInitializeComponent()
        {
            DataContext = ViewModel;
            recommand.ItemClick += OnRecommandClick;
        }
        private void OnRecommandClick(object sender, ViewRoutedEventArgs e)
        {
            try
            {
                if (e.ClickItem is ListViewItem item && item.Content is ChannelFeed feed)
                    App.Mapper.NavigateToPlayer(feed.Aid, PlayMode.Video);
            }
            catch { }
        }
        public override void Callback()
        {
            if (Data is Tuple<string, string> tuple)
            {
                RunOnUiThread(async () =>
                {
                    await ViewModel.LoadData(tuple.Item1, tuple.Item2);
                    await ViewModel.LoadDymamic(tuple.Item2);
                });
            }
        }
        protected override void OnClosing(Avalonia.Controls.WindowClosingEventArgs e)
        {
            recommand.ItemClick -= OnRecommandClick;
            base.OnClosing(e);
        }
    }
}